package com.wbt.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

public class TestSentinel {
    public static void main(String[] args) {
        Set<String> sentinel = new HashSet<>();
        sentinel.add("192.168.172.201:26379");
        sentinel.add("192.168.172.202:26379");
        sentinel.add("192.168.172.203:26379");
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(2);
        config.setMaxTotal(5);
        JedisSentinelPool mymaster = new JedisSentinelPool("mymaster", sentinel, config);



        int i =1;
        boolean fag = false;
        Long startTime = 0l;
        while (true){
            try {
                Jedis jedis = mymaster.getResource();
                jedis.set("jedis","jedis" + i);
                i++;
                String jedis1 = jedis.get("jedis");
                System.out.println(jedis1);
                Thread.sleep(1000);
                jedis.close();
                if(fag){
                    int ss = (int) ((System.currentTimeMillis() - startTime)/1000);
                    System.out.println(ss);
                    fag = false;
                }
            }catch (Exception e){
                if (!fag){
                    startTime = System.currentTimeMillis();
                    fag = true;
                }
                e.printStackTrace();
            }
        }



    }

    public static void getRead(){

    }
}
